#include "type_mt.h"

#include <bool.h>
#include <bstring.h>
#include <enumeration.h>
#include <number.h>

#include <QtTest/QTest>

using namespace core;
using namespace moduletest;

void Type_mt::matches()
{
    Bool b1(true), b2(false);
    Number n1(0), n2(1);
    BasicString s1("myFirstString"), s2("mySecondString");

    EnumerationValues vals;
    vals << "black" << "red" << "blue";
    Enumeration c1("EColors", vals), c2("EColors", vals);

    // valid
    QVERIFY(b1.matches(b2));
    QVERIFY(n1.matches(n2));
    QVERIFY(s1.matches(s2));
    QVERIFY(c1.matches(c2));
    // not valid
    QVERIFY(!n1.matches(b1));
    QVERIFY(!n1.matches(s1));
    QVERIFY(!n1.matches(c1));
    QVERIFY(!b1.matches(s1));
    QVERIFY(!b1.matches(c1));
    QVERIFY(!b1.matches(n1));
    QVERIFY(!s1.matches(n1));
    QVERIFY(!s1.matches(b1));
    QVERIFY(!s1.matches(c1));
    QVERIFY(!c1.matches(n1));
    QVERIFY(!c1.matches(b1));
    QVERIFY(!c1.matches(s1));
}

void Type_mt::operatorEquals()
{
    Bool b1(true), b2(false);
    Number n1(0), n2(1);
    BasicString s1("myFirstString"), s2("mySecondString");

    EnumerationValues vals;
    vals << "black" << "red" << "blue";
    Enumeration c1("EColors", vals), c2("EColors", vals);
    c1.setValue("black");

    // not equal
    QVERIFY(!(b1 == b2));
    QVERIFY(!(n1 == n2));
    QVERIFY(!(s1 == s2));
    QVERIFY(!(c1 == c2));

    QVERIFY(!(b1 == n1));
    QVERIFY(!(b1 == s1));
    QVERIFY(!(b1 == c1));

    QVERIFY(!(n1 == b1));
    QVERIFY(!(n1 == s1));
    QVERIFY(!(n1 == c1));

    QVERIFY(!(s1 == b1));
    QVERIFY(!(s1 == n1));
    QVERIFY(!(s1 == c1));

    QVERIFY(!(c1 == b1));
    QVERIFY(!(c1 == n1));
    QVERIFY(!(c1 == s1));

    b2.setValue(true);
    n2.setValue(0);
    s2.setValue("myFirstString");
    c2.setValue("black");

    // equal
    QVERIFY(b1 == b2);
    QVERIFY(n1 == n2);
    QVERIFY(s1 == s2);
    QVERIFY(c1 == c2);
}

void Type_mt::operatorNotEquals()
{
    Bool b1(true), b2(false);
    Number n1(0), n2(1);
    BasicString s1("myFirstString"), s2("mySecondString");

    EnumerationValues vals;
    vals << "black" << "red" << "blue";
    Enumeration c1("EColors", vals), c2("EColors", vals);
    c1.setValue("black");

    // not equal
    QVERIFY(b1 != b2);
    QVERIFY(n1 != n2);
    QVERIFY(s1 != s2);
    QVERIFY(c1 != c2);

    QVERIFY(b1 != n1);
    QVERIFY(b1 != s1);
    QVERIFY(b1 != c1);

    QVERIFY(n1 != b1);
    QVERIFY(n1 != s1);
    QVERIFY(n1 != c1);

    QVERIFY(s1 != b1);
    QVERIFY(s1 != n1);
    QVERIFY(s1 != c1);

    QVERIFY(c1 != b1);
    QVERIFY(c1 != n1);
    QVERIFY(c1 != s1);

    b2.setValue(true);
    n2.setValue(0);
    s2.setValue("myFirstString");
    c2.setValue("black");

    // equal
    QVERIFY(!(b1 != b2));
    QVERIFY(!(n1 != n2));
    QVERIFY(!(s1 != s2));
    QVERIFY(!(c1 != c2));
}
